package com.lalilu.lmedia.repository

import com.lalilu.lmedia.entity.LPlaylist
import com.lalilu.lmedia.entity.LSong
import com.lalilu.lmedia.entity.SongInPlaylist
import kotlinx.coroutines.flow.Flow

interface PlaylistRepository {
    fun getAllPlaylistFlow(): Flow<List<LPlaylist>>
    fun getAllPlaylistWithDetailFlow(): Flow<List<LPlaylist>>
    fun isSongContainInPlaylist(mediaId: String, pId: Long): Flow<Boolean>
    fun getSongInPlaylistsFlowById(pId: Long): Flow<List<SongInPlaylist>>
    fun getSongInPlaylistsById(pId: Long): List<SongInPlaylist>
    fun getPlaylistById(pId: Long): Flow<LPlaylist>

    /**
     * 保存歌单
     *
     * @param playlist 歌单对象
     */
    fun savePlaylist(playlist: LPlaylist)

    /**
     * 删除歌单
     *
     * @param playlist 歌单对象
     */
    fun deletePlaylist(playlist: LPlaylist)

    /**
     * 删除歌单
     *
     * @param playlists 歌单对象
     */
    fun deletePlaylists(playlists: List<LPlaylist>)

    /**
     * 通过ID将歌曲保存至指定歌单中
     *
     * @param pId 歌单ID
     */
    fun saveSongIntoPlaylist(pId: Long, mediaId: String)

    /**
     * 将多首歌曲存入多个歌单内
     */
    fun saveSongsIntoPlaylists(pIds: List<Long>, mediaIds: List<String>)

    /**
     * 通过ID将歌曲从指定歌单中删除
     *
     * @param pId 歌单ID
     */
    fun deleteSongFromPlaylist(pId: Long, mediaId: String)

    /**
     * 将多首歌曲从playlist中删除
     */
    fun deleteSongsFromPlaylist(songs: List<LSong>, playlist: LPlaylist)

    /**
     * 根据传入的列表重排数据库中歌单列表的顺序
     *
     * @param orderedList 指定顺序的列表
     */
    fun reorderPlaylist(orderedList: List<LPlaylist>)

    /**
     * 根据传入的列表重排数据库中歌单内的歌曲的顺序
     *
     * @param orderedList 指定顺序的列表
     */
    fun reorderSongInPlaylist(orderedList: List<SongInPlaylist>)

    /**
     * 移动指定歌单到目标歌单的前或后
     *
     * @param playlist          所需要移动的歌单
     * @param playlistTarget    所需要移动的歌单
     * @param beforeTarget      是否移动到目标的前面
     */
    fun movePlaylist(playlist: LPlaylist, playlistTarget: LPlaylist, beforeTarget: Boolean)

    /**
     * 移动歌单内指定歌曲到目标歌曲的前或后
     *
     * @param item              所需要移动的歌曲
     * @param target            所需要移动的歌曲
     * @param beforeTarget      是否移动到目标的前面
     */
    fun moveSongInPlaylist(item: SongInPlaylist, target: SongInPlaylist, beforeTarget: Boolean)
}